package com.project.nimsen.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.project.nimsen.constant.ModelConstant;

/**
 * 映射"/pub/**"路径
 * */
public class NimsenInterceptor implements HandlerInterceptor {
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String useagent = request.getHeader("User-Agent").toLowerCase();
		//配置用户登录的终端
		HttpSession session = request.getSession();
		//访问终端判断
		if(session.getAttribute("access_terminal")!=null)
			return true;
		String access_terminal = ModelConstant.PC;
		if(useagent.contains("ipad"))
			access_terminal = ModelConstant.PAD;
		if(useagent.contains("iphone"))
			access_terminal = ModelConstant.PHONE;
		if(useagent.contains("android"))
			access_terminal = ModelConstant.PHONE;
		session.setAttribute("access_terminal", access_terminal);
		return true;
	}
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}
}
